Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

187
Views
¿Por qué mi código devuelve "[indefinido, indefinido, indefinido]"?

 function sumAll(arr) { arr.sort(); let lum = []; for (let i = arr[1]; i > arr[0]; i--) { lum.push(arr[i]); } return lum; } console.log(sumAll([1, 4]));

Quiero que mi código haga 4-3, luego agregue el resultado a lum y así sucesivamente hasta que llegue a 1, pero estoy atascado en este punto. No sé por qué devuelve undefined .

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Estás presionando arr[i] en el resultado:

 lum.push(arr[i]);

Entonces, por ejemplo, cuando i es 4 (porque arr[1] es 4), ¿cuál es el valor arr[4] que estás empujando al resultado? No está undefined en la matriz proporcionada. ¿Sospecho que querías empujar i al resultado?:

 lum.push(i);

Por ejemplo:

 function sumAll(arr) { arr.sort(); let lum = []; for (let i = arr[1]; i > arr[0]; i--) { lum.push(i); } return lum; } console.log(sumAll([1, 4]));

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!